<template>
  <div class="welcome-container">    <div class="welcome-header">
      <h1>欢迎使用金融工具平台</h1>
      <p class="welcome-date">
        <span class="date-label">服务器时间:</span>
        <span class="date-value">{{ serverDate }}</span>
      </p>
    </div>
    
    <div class="features-grid">
      <div class="feature-card card-primary">
        <div class="feature-icon bg-gradient-blue">💰</div>
        <h3 class="text-primary">贷款计算器</h3>
        <p>计算等额本息和等额本金还款方式下的月供和总还款额</p>
        <button class="feature-btn btn-light-blue" @click="goTo('/loan-calculator')">立即使用</button>
      </div>      <div class="feature-card card-secondary">
        <div class="feature-icon bg-gradient-green">📈</div>
        <h3 class="text-secondary">现金流估值</h3>
        <p>基于DCF方法分析公司现金流，评估企业内在价值</p>
        <button class="feature-btn btn-light-blue" @click="goTo('/stock-valuation')">开始分析</button>
      </div>
        <div class="feature-card card-accent">
        <div class="feature-icon bg-gradient-orange">📊</div>
        <h3 class="text-accent">AI问答</h3>
        <p>利用人工智能解答您的金融问题</p>
        <button class="feature-btn btn-light-blue" @click="goTo('/ai-chat')">开始对话</button>
      </div>
        <div class="feature-card card-info">        <div class="feature-icon bg-gradient-cool">💬</div>        <h3 class="text-info">发帖讨论</h3>
        <p>与其他用户分享金融经验和投资心得</p>
        <button class="feature-btn btn-light-blue" @click="goTo('/post-integrated')">浏览讨论</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import axios from 'axios'

const router = useRouter()
const serverDate = ref('')
let timeInterval = null

function goTo(path) {
  router.push(path)
}

// 获取服务器时间的函数
async function fetchServerTime() {
  try {
    const res = await axios.get('/api/server-time')
    serverDate.value = res.data.server_time
  } catch (e) {
    serverDate.value = '获取服务器时间失败'
  }
}

onMounted(async () => {
  // 立即获取一次服务器时间
  await fetchServerTime()
  
  // 设置定时器，每秒更新一次
  timeInterval = setInterval(fetchServerTime, 1000)
})

onUnmounted(() => {
  // 组件卸载时清理定时器
  if (timeInterval) {
    clearInterval(timeInterval)
  }
})
</script>

<style scoped>
.welcome-container {
  padding: 2rem 1rem;
  max-width: 1280px;
  margin: 0 auto;
  background: linear-gradient(to bottom, rgba(94, 234, 212, 0.05), rgba(94, 234, 212, 0.02));
  min-height: 100%;
  border-radius: var(--radius-md);
}

.welcome-header {
  text-align: center;
  margin-bottom: 2rem;
  background-color: white;
  padding: 1.5rem 2rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.welcome-header h1 {  font-size: 2.25rem;
  font-weight: 700;
  color: #000000; /* 设置为纯黑色 */
  margin-bottom: 0.5rem;
  position: relative;
}

.welcome-header h1::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 3px;
  background: var(--gradient-blue);
  border-radius: 3px;
}

.welcome-date {
  display: inline-block;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--info-dark);
  margin-top: 0.75rem;
  background-color: var(--neutral-50);
  padding: 0.4rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 0 auto 2.5rem;
}

.feature-card {
  background: white;
  border-radius: var(--radius-md);
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  transition: all 0.3s;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  height: 100%;
  border-top: 3px solid transparent;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
}

.card-primary {
  border-top: 3px solid var(--primary-color);
}

.card-secondary {
  border-top: 3px solid var(--secondary-color);
}

.card-accent {
  border-top: 3px solid var(--accent-color);
}

.card-info {
  border-top: 3px solid var(--info-color);
}

.card-primary h3 {
  color: var(--primary-color);
}

.card-secondary h3 {
  color: var(--secondary-color);
}

.card-accent h3 {
  color: var(--accent-color);
}

.card-info h3 {
  color: var(--info-color);
}

.feature-card::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 100px;
  height: 100px;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 50%;
  transform: translate(50%, -50%);
  z-index: 0;
}

.feature-icon {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.25rem;
  margin-bottom: 1.25rem;
  color: white;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
}

.feature-card h3 {
  font-size: 1.35rem;
  margin-bottom: 0.75rem;
  position: relative;
  z-index: 1;
}

.feature-card p {
  color: var(--neutral-800); /* 修改为更深的颜色以提高可读性 */
  margin-bottom: 1.75rem;
  flex-grow: 1;
  line-height: 1.5;
  position: relative;
  z-index: 1;
  font-weight: 500; /* 增加字重 */
}

.feature-btn {
  padding: 0.7rem 1.75rem;
  border-radius: var(--radius);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: white;
  font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 1;
  border: none;
}

.feature-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.btn-light-blue {
  background-color: #6ea8fe;
  color: white;
  transition: all 0.2s;
}

.btn-light-blue:hover {
  background-color: #3a7bd5;
}

.btn-primary {
  background-color: var(--primary-color);
}

.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-accent {
  background-color: var(--accent-color);
}

.btn-accent:hover {
  background-color: var(--accent-dark);
}

.btn-info {
  background-color: var(--info-color);
}

.btn-info:hover {
  background-color: var(--info-dark);
}

/* 数据统计卡片 */
.quick-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin: 3rem auto 0;
  padding: 0 1rem;
}

.stat-card {
  border-radius: var(--radius-md);
  padding: 1.75rem;
  color: #000000; /* 修改为黑色文字 */
  text-align: center;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
  transition: all 0.3s;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.stat-card h4 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: #000000; /* 修改为黑色文字 */
  position: relative;
  z-index: 1;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.stat-card::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 60%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.1), transparent);
  z-index: 0;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  position: relative;
  z-index: 1;
  color: #000000; /* 确保数值为黑色 */
}

.stat-change {
  font-size: 0.95rem;
  font-weight: 500;
  position: relative;
  z-index: 1;
  color: #000000; /* 确保为黑色 */
}

.stat-label {
  font-size: 0.95rem;
  opacity: 0.95;
  position: relative;
  z-index: 1;
  color: #000000; /* 确保为黑色 */
}

.positive {
  color: #000000; /* 修改为黑色 */
}  

.negative {
  color: #000000; /* 修改为黑色 */
}

.text-primary {
  color: var(--primary-color);
}

.text-secondary {
  color: var(--secondary-dark);
}

.text-accent {
  color: var(--accent-dark);
}

.text-info {
  color: var(--info-color);
}

@media (max-width: 1024px) {
  .welcome-header h1 {
    font-size: 2rem;
  }
  
  .features-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
  
  .quick-stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
  }
}

@media (max-width: 768px) {
  .welcome-container {
    padding: 1.5rem 1rem;
  }

  .welcome-header {
    padding: 1.5rem;
    margin-bottom: 2rem;
  }
  
  .welcome-header h1 {
    font-size: 1.75rem;
  }
  
  .features-grid, .quick-stats {
    grid-template-columns: 1fr;
  }
  
  .feature-card {
    padding: 1.5rem;
  }
}
</style>